<?php

/**
 * planning_tache form.
 *
 * @package    gesp
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class planning_tacheForm extends Baseplanning_tacheForm {
	public function configure() {
		unset($this['plntac_charge_consommee']);
		unset($this['plntac_charge_restante']);
		unset($this['plntac_date_fin']);
		unset($this['plntac_etat']);

		//-------------------------------------------------------------
		// redéfinition des widgets
		$this->setWidget('plntac_prj_id', new sfWidgetFormInputHidden());
		$this->setWidget('plntac_plnphs_id', new sfWidgetFormInputHidden());
		$this->setWidget('plntac_ordre', new sfWidgetFormInputHidden());
		// $date_debut = date('d/m/Y');
		$this->setWidget('plntac_date_debut', new DatePickerWidget());
		$this->setWidget('plntac_date_echeance', new DatePickerWidget());
		
		//-------------------------------------------------------------
		// redéfinition des validateurs
		$this->validatorSchema['plntac_libelle']->setOption('required', true);
		$this->setValidator(
			'plntac_date_debut',
			new ValidatorDate(array(
				'required' => true,
				'date_format' => '/^(?P<day>\d+)\/(?P<month>\d+)(\/(?P<year>\d+))?/',
				),
				array(
				'bad_format' => "format de date invalide : dd/mm[/yyyy]",
				)
			)
		);
		$this->setValidator(
			'plntac_date_echeance',
			new ValidatorDate(array(
				'required' => false,
				'date_format' => '/^(?P<day>\d+)\/(?P<month>\d+)(\/(?P<year>\d+))?/',
				),
				array(
				'bad_format' => "format de date invalide : dd/mm[/yyyy]",
				)
			)
		);
		
		// modification des messages d'erreur
		$this->validatorSchema['plntac_libelle']->setMessage('required', 'Champ requis');

		$this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
			new ValidatorTachePlanning('plntac_date_debut', array()),
			new ValidatorTachePlanning('plntac_date_echeance', array()),
		)));
		
		//-------------------------------------------------------------
		// redéfinition des libellés
		$this->widgetSchema->setLabels(array(
			'plntac_libelle' => 'Tâche',
			'plntac_date_debut' => 'Date de début',
			'plntac_date_echeance' => 'Date d\'échéance',
			'plntac_charge_estimee' => 'Charge estimée',
		));
		
	}

	public function doSave($con = null) {
		if ($this->getObject()->getPlntacChargeRestante() == '') {
			$this->values['plntac_charge_restante'] = $this->getValue('plntac_charge_estimee');
		}
		parent::doSave($con);
	}
	
}
